using System.Collections.Generic;


namespace Super
{
	public class FWSetManager : SaveSingle<FWSetManager>
	{

		public List<FWOptionNode> optionNames = new List<FWOptionNode>();

		public Dictionary<string, Dictionary<string, FWSettingNode>> options = new Dictionary<string, Dictionary<string, FWSettingNode>>();

		/// <summary>
		/// 获取选项
		/// </summary>
		/// <param name="optionKey"></param>
		/// <returns></returns>
		public static Dictionary<string, FWSettingNode> GetOption(string optionKey)
		{
			return Ins.options[optionKey];
		}

		public static Dictionary<string, FWSettingNode> GetOption(int index)
		{
			var option = Ins.optionNames[index];
			return Ins.options[option.key];
		}

		public static int GetOptionNum()
		{
			return Ins.options.Count;
		}

		public static void AddOption(string key, string name, FWSetShowType showType)
		{
			Ins.options.Add(key, new Dictionary<string, FWSettingNode>());
			Ins.optionNames.Add(new FWOptionNode(key, name, showType));
			SaveData();
		}

		public static void RemoveOption(int index)
		{
			var option = Ins.optionNames[index];
			Ins.options.Remove(option.key);
			Ins.optionNames.RemoveAt(index);
		}

		/// <summary>
		/// 检测选项是否存在
		/// </summary>
		/// <param name="optionKey"></param>
		/// <returns></returns>
		public static bool CheckIfOption(string optionKey)
		{
			if (!Ins.options.ContainsKey(optionKey))
			{
				return false;
			}

			return true;
		}

		/// <summary>
		/// 检测配置是否存在
		/// </summary>
		/// <param name="optionKey"></param>
		/// <param name="key"></param>
		/// <returns></returns>
		public static bool CheckIfSetting(string optionKey, string key)
		{
			if (!CheckIfOption(optionKey))
			{
				return false;
			}

			var dict = Ins.options[optionKey];
			if (!dict.ContainsKey(key))
			{
				return false;
			}

			return true;
		}

		/// <summary>
		/// 获取对应设置的值
		/// </summary>
		/// <param name="optionKey"></param>
		/// <param name="key"></param>
		/// <returns></returns>
		public static FWSettingNode GetSettingNode(string optionKey, string key)
		{
			var dict = Ins.options[optionKey];
			return dict[key];
		}

		/// <summary>
		/// 获取功能开关状态
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public static bool GetSwitchState(string key)
		{
			string optionKey = "FuncSwitch";
			if (!CheckIfSetting(optionKey, key))
			{
				return false;
			}

			return GetSettingNode(optionKey, key).isActive;
		}

		/// <summary>
		/// 获取配置数量
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public static int GetDefaultNum(string key)
		{
			string optionKey = "DefaultNum";
			if (!CheckIfSetting(optionKey, key))
			{
				return 0;
			}

			return GetSettingNode(optionKey, key).numInt;
		}

		/// <summary>
		/// 获取初始化开关状态
		/// </summary>
		/// <param name="key"></param>
		/// <returns></returns>
		public static bool GetInitState(string key)
		{
			string optionKey = "Init";
			if (!CheckIfSetting(optionKey, key))
			{
				return false;
			}

			return GetSettingNode(optionKey, key).isActive;
		}
	}

}
